﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OutputCache
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            form1.Controls.Add(new Label() { Text = DateTime.Now.ToLongTimeString(), CssClass = "time-span" });
            
            //Count this page loads
            if (Session["DefaultPageLoaded"] == null)
            {
                Session["DefaultPageLoaded"] = "0";
            }
            string tmp = (string) Session["DefaultPageLoaded"];
            int count = Convert.ToInt32(tmp) + 1;
            Session["DefaultPageLoaded"] = count.ToString();


            //Count ttal page loads
            if (Application["TotalPageLoads"] == null)
            {
                Application["TotalPageLoads"] = "0";
            }

            Application["TotalPageLoads"] = Convert.ToInt32(Application["TotalPageLoads"]) + 1;


            //create two controls to display the total load results
            if (Page.FindControl("uiTimeKeeperLoadTotal") == null)
            {
                string s = "Antal af Extern tids kontrol loaded: " + Session["TimeKeeperControlLoaded"];
                form1.Controls.Add(new Label() { Text = s, CssClass = "load-count", ID = "uiTimeKeeperLoadTotal" });
            }
            else
            {
                Control c = Page.FindControl("uiTimeKeeperLoadTotal");
                if (c.GetType() == typeof(Label))
                {
                    Label l = (Label)c;
                    l.Text = "Antal af Extern tids kontrol loaded: " + Session["TimeKeeperControlLoaded"];
                }
            }
            if (Page.FindControl("uiDefaultLoadTotal") == null)
            {
                //form1.Controls.Add(new Label() { Text = "", CssClass = "load-count", ID = "uiDefaultLoadTotal" });
            }
            uiTimekeeper.DisplayControlLoaded();

        }
    }
}